package com.mind.core.server;

import org.apache.log4j.Logger;

/**
 * 游戏服务器运行时数据
 * 
 * 
 * 
 */
public class GameServerRuntime {
	private static final Logger logger = Logger.getLogger(GameServerRuntime.class);
	/**
	 * 服务是否已经开放
	 */
	private static volatile boolean open;
	/**
	 * 服务是否正在关闭
	 */
	private static volatile boolean shutdowning;
	/** 是否进行写流量控制,默认为true,即进行写流量的控制 **/
	private static volatile boolean writeTrafficControl = true;
	/** 是否进行读浏览控制,默认为true,即进行读流量的控制 */
	private static volatile boolean readTrafficControl = true;
	/** 在写缓冲中的最大字字数,超过此限制将丢弃新的消息 */
	public static final int MAX_WRITE_TRAFFIC_BYTES = 200 * 1024;

	private GameServerRuntime() {

	}

	/**
	 * 检查服务是否已经开放,只有在已经开放的情况下才能接收玩家的连接
	 * 
	 * @return the open
	 */
	public static boolean isOpen() {
		return open;
	}

	/**
	 * 打开服务
	 * 
	 */
	public static void setOpenOn() {
		open = true;
	}

	/**
	 * 关闭服务
	 */
	public static void setOpenOff() {
		open = false;
	}

	/**
	 * 设置服务器正在关闭
	 */
	public static void setShutdowning() {
		shutdowning = true;
	}

	/**
	 * 服务器是否正在关闭
	 * 
	 * @return
	 */
	public static boolean isShutdowning() {
		return shutdowning;
	}

	/**
	 * 是否对玩家Session进行写流量控制
	 * 
	 * @return the writeTrafficControl
	 */
	public static boolean isWriteTrafficControl() {
		return writeTrafficControl;
	}

	/**
	 * 设置是否对玩家进行写流量控制
	 * 
	 * @param writeTrafficControl
	 *            the writeTrafficControl to set
	 */
	public static void setWriteTrafficControl(boolean writeTrafficControl) {
		GameServerRuntime.writeTrafficControl = writeTrafficControl;
	}

	/**
	 * 是否对玩家session进行读流量的控制
	 * 
	 * @return the readTrafficControl
	 */
	public static boolean isReadTrafficControl() {
		return readTrafficControl;
	}

	/**
	 * 设置是否对玩家进行读流量的控制
	 * 
	 * @param readTrafficControl
	 *            the readTrafficControl to set
	 */
	public static void setReadTrafficControl(boolean readTrafficControl) {
		GameServerRuntime.readTrafficControl = readTrafficControl;
	}
	public static void infoJvmStatus(){
		logger.info("jvm:free="+Runtime.getRuntime().freeMemory()/(1024*1024)+ "MB"
				+",max="+Runtime.getRuntime().maxMemory()/(1024*1024)+ "MB"
				+",total="+Runtime.getRuntime().totalMemory()/(1024*1024)+ "MB");
	}
}
